import Mock from 'mockjs'

// 项目标签
const tags = ['Web前端', '算法', '人工智能', '移动开发', '后端开发', '数据库']

// 项目列表
const projects = [
  {
    id: 1,
    title: '蓝桥杯Web组备赛资料',
    description: '包含HTML、CSS、JavaScript、Vue.js等前端开发技术的学习资料和实战项目',
    tags: ['Web前端'],
    downloadUrl: '/projectLibrary/lanqiao-web/README.md',
    updateTime: '2024-01-04',
    downloadCount: 156
  },
  {
    id: 2,
    title: 'ACM程序设计竞赛资料',
    description: '包含基础算法、数据结构、高级算法等竞赛相关的学习资料和刷题建议',
    tags: ['算法'],
    downloadUrl: '/projectLibrary/acm/README.md',
    updateTime: '2024-01-03',
    downloadCount: 89
  },
  {
    id: 3,
    title: 'Vue.js项目实战教程',
    description: '基于Vue 3和Element Plus的后台管理系统开发教程，包含完整源码',
    tags: ['Web前端'],
    downloadUrl: '/projectLibrary/vue-admin/README.md',
    updateTime: '2024-01-02',
    downloadCount: 235
  },
  {
    id: 4,
    title: '机器学习算法实现',
    description: '常用机器学习算法的Python实现，包含详细注释和示例数据',
    tags: ['算法', '人工智能'],
    downloadUrl: '/projectLibrary/ml-algorithms/README.md',
    updateTime: '2024-01-01',
    downloadCount: 167
  },
  {
    id: 5,
    title: 'Flutter移动应用开发',
    description: '跨平台移动应用开发教程，包含UI设计和状态管理的最佳实践',
    tags: ['移动开发'],
    downloadUrl: '/projectLibrary/flutter-app/README.md',
    updateTime: '2023-12-31',
    downloadCount: 143
  }
]

// Mock API 响应
Mock.mock(/\/project\/tags/, 'get', () => {
  return {
    code: 200,
    data: tags,
    message: 'success'
  }
})

Mock.mock(/\/project\/list/, 'get', (options) => {
  const { url } = options
  const params = new URLSearchParams(url.split('?')[1])
  const tag = params.get('tag')
  const keyword = params.get('keyword')
  
  let filteredProjects = [...projects]
  
  // 标签筛选
  if (tag && tag !== '全部') {
    filteredProjects = filteredProjects.filter(project => 
      project.tags.includes(tag)
    )
  }
  
  // 关键词搜索
  if (keyword) {
    const loweredKeyword = keyword.toLowerCase()
    filteredProjects = filteredProjects.filter(project =>
      project.title.toLowerCase().includes(loweredKeyword) ||
      project.description.toLowerCase().includes(loweredKeyword)
    )
  }
  
  return {
    code: 200,
    data: filteredProjects,
    message: 'success'
  }
})

export default {
  tags,
  projects
}
